package com.wxsoft.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * @author chenliang
 *
 */
public class UnitCodeUtil {

	private static long counter = 0;
	private static String dateFormat = "yyMMdd";
	private static String lastDate = new SimpleDateFormat(dateFormat).format(new Date()) ;

	/**
	 * 
	 * @Description:TODO
	 * @author: chenliang
	 * @time:2018-3-14 下午9:37:13
	 */
	public synchronized static String getCode(){
		String date = new SimpleDateFormat(dateFormat).format(new Date()) ;
		if(!lastDate.equals(date)){
			counter = 0;
		}
		String sequ = new DecimalFormat("0000").format(counter++);
		return date + sequ ;
	}
	
	public static void main(String [] s){
		System.out.println(getCode());
	}
	
	
}
